<?php
/**
 * Created by PhpStorm.
 * User: 87393
 * Date: 2019-03-26
 * Time: 23:16
 */

namespace App\Http\Repositories\Daos\Impls;


use App\Http\Repositories\Daos\ISystemDao;
use App\Http\Repositories\Eloquent\System;

class SystemDao extends BaseDao implements ISystemDao
{
    public function __construct(System $model)
    {
        parent::__construct($model);
    }

    public function search($search) {
        $filterMap = $this->model->newQuery();
        if (isset($search['name'])) {
            $filterMap->where('name','like',$search['name']);
        }
        return $filterMap;
    }

    public function lists($search, $page, $size)
    {
        $filterMap = $this->model->newQuery();
        if (isset($search['name']) && !empty($search['name'])) {
            $filterMap->where('name', 'LIKE', '%'.$search['name'].'%');
        }
        $order = ['created_at'=>'DESC','id'=>'DESC'];
        return $this->page($filterMap, $page, $size, $order);
    }

    public function byName($name, $exceptId = 0)
    {
        $filterMap = $this->model->newQuery();
        if ($exceptId) {
            $filterMap->where('id','!=', $exceptId);
        }
        $filterMap->where('name',$name);
        return $filterMap->first();
    }

}